﻿using CSharpDay14.Data.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations; //used for AddOrUpdate()
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDay14.Data
{
    public static class Seeder
    {
        public static void Seed(ApplicationDbContext db, bool seedUserProducts = true)
        {
            if (seedUserProducts) SeedUserProducts(db);
        }

        private static void SeedUserProducts(ApplicationDbContext db)
        {
            User Jeremy = new User()
            {
                Id = 1,
                Name = "Jeremy",
                Address = "550 Somewhere Awesome Place"
            };
            User Bill = new User()
            {
                Id = 2,
                Name = "Bill",
                Address = "123 Another Place"
            };
            User Ricky = new User()
            {
                Id = 3,
                Name = "Ricky",
                Address = "333 Somewhere Awesome Place"
            };
            User Jason = new User()
            {
                Id = 4,
                Name = "Jason",
                Address = "987 Another Place"
            };

            db.Products.AddOrUpdate(x => x.Id,
                new Product() { Id = 1, Price = 5.50, Title = "This is cool", Users = new List<User>() { Jeremy, Bill } },
                new Product() { Id = 2, Price = 7.89, Title = "This is better", Users = new List<User>() { Jeremy, Bill, Ricky } },
                new Product() { Id = 3, Price = 32.98, Title = "Not worth the money", Users = new List<User>() { Jeremy, Bill, Jason } },
                new Product() { Id = 4, Price = 127.54, Title = "Do I need to keep seeding these?", Users = new List<User>() { Jason, Ricky } },
                new Product() { Id = 5, Price = 9835.7, Title = "This is a test", Users = new List<User>() { Jason, Ricky, Bill } },
                new Product() { Id = 6, Price = 1346.8, Title = "Everyone loves this", Users = new List<User>() { Jason, Bill, Ricky, Jeremy } },
                new Product() { Id = 7, Price = 1894521.78, Title = "This is amazing, please buy it", Users = new List<User>() { Jason, Ricky, Jeremy } }
            );
        }
    }
}